package com.example.controller.frontend;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.example.common.ApiResult;

import com.example.entity.Carousel;
import com.example.service.CarouselService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

@RestController
@RequestMapping("/api/carousel")
@Api(tags = "轮播管理")
public class FCarouselController {

    @Resource
    private CarouselService carouselService;


    @ApiOperation("按标题分页查询轮播列表")
    @GetMapping("/queryPage")
    /*
paramType:
 1、@RequestParam     paramType="query"
 2、@PathVariable     paramType="path"
 3、 @RequestBody     paramType="body/form"
     */
    @ApiImplicitParams(
            value = {
                    @ApiImplicitParam(name = "imgTitle",value = "标题",required = false,paramType = "query",dataType = "String",defaultValue = ""),
                    @ApiImplicitParam(name = "page",value = "页码",required = true,paramType = "query",dataType = "Integer",defaultValue = "1"),
                    @ApiImplicitParam(name = "size",value = "页容量",required = true,paramType = "query",dataType = "Integer",defaultValue = "10")
            }
    )
    public ApiResult queryPage(
            @RequestParam(required = false,defaultValue = "") String imgTitle,@RequestParam(defaultValue = "1")Integer page,
            @RequestParam(defaultValue = "10") Integer size){
        Page<Carousel> itemPage = new Page<>(page, size);
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.like("img_title",imgTitle);
        queryWrapper.orderByDesc("create_date");
        Page<Carousel> result = carouselService.page(itemPage,queryWrapper);
        PageDTO<Carousel> pageDTO = new PageDTO<>();
        pageDTO.setTotal(result.getTotal());
        pageDTO.setRecords(result.getRecords());
        return ApiResult.ok(pageDTO);
    }


    @ApiOperation("新增轮播图")
    @PostMapping("/addCarousel")
    public ApiResult addCarousel(@RequestBody Carousel carousel){

        return null;
    }


    @ApiOperation("删除轮播图")
    @DeleteMapping("/deleteCarousel/{id}")
    public ApiResult deleteCarousel(@PathVariable Integer id){
        return null;
    }


    @ApiOperation("修改轮播图")
    @PutMapping("/updateCarousel")
    public ApiResult updateCarousel(@RequestBody Carousel carousel){
        return null;
    }


    @ApiOperation("获取轮播图详情")
    @GetMapping("/query/{id}")
    public ApiResult queryCarousel(@PathVariable Integer id){
        return null;
    }
}